﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.WebControls;
using JuridicoWeb.BisinessLayer.Service;
using JuridicoDataLibrary.Model;

public partial class Admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnLogin_Click(object sender, ImageClickEventArgs e)
    {
        Page.Validate("vgLogin");

        if (Page.IsValid)
        {
            int index = 0;
            string login = txtLogin.Text;
            string senha = txtSenha.Text;

            if (new UsuarioService().ValidarUsuario(login, senha))
            {
                lblMensagem.Visible = false;
                Session.Clear();

                IList usuario = new UsuarioService().ListarUsuarios(login);
                Session["idUsuario"] = ((Usuario)usuario[index]).nCodUsuario;
                Session["nomeUsuario"] = ((Usuario)usuario[index]).sNome;
                Session["operacoes"] = ((Usuario)usuario[index]).sOperacoesPermitidas;

                FormsAuthentication.RedirectFromLoginPage(login, true);
            }
            else
            {
                lblMensagem.Text = Resources.JuridicoWeb.LoginErrorMessage;
                lblMensagem.Visible = true;
            }
        }
    }
}
